package com.coderman.domainservice.blogtopic.domain.ability;

import com.alibaba.fastjson.JSON;
import com.coderman.domainservice.blogtopic.domain.model.entity.IndicesStatisticsBO;
import com.coderman.domainservice.blogtopic.infrast.cache.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Description:
 * date: 2021/3/31
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 * 这里当作博客技术统计能力，统计评论数，收藏数，阅读数
 * 当前基于博客维度的数据统计可以放在表中，这里放在redis中，作为演示
 */
@Service
public class BlogIndiceService {
    @Autowired
    private RedisService redisService;
    /**
     * @param inCre 是否递增
     * @param blogId
     * @param key  统计项
     */
   public void updateCount(final long blogId,final String key,final boolean inCre){
       String mapStr =  redisService.get(blogId+"");
       Map<String,Integer> indiceMap = JSON.parseObject(mapStr,Map.class);
       if(inCre){
           indiceMap.put(key,indiceMap.get(key)+1);
       }else {
           indiceMap.put(key,indiceMap.get(key)-1);
       }
    }

    /**
     * 针对该博客获取统计数据
     * @param blogId
     * @return
     */
    public List<IndicesStatisticsBO> getIndiceList(long blogId) {
        redisService.get(blogId+"");
        return null;
    }


}
